package com.pdg.dungeondelver.engine;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.pdg.dungeondelver.configuration.Configuration;

public class LayerCell {
	private LayerColumn layerColumn;
	private TerrainInstance terrain = null;
	private Map<LayerDirections,LayerCell> neighbors = new HashMap<LayerDirections,LayerCell>();
	public void setNeighbor(LayerDirections theDirection,LayerCell theCell){
		neighbors.put(theDirection, theCell);
	}
	public LayerCell getNeighbor(LayerDirections theDirection){
		return neighbors.get(theDirection);
	}
	public TerrainInstance getTerrain(){
		return terrain;
	}
	public void setTerrain(TerrainInstance theTerrain){
		terrain = theTerrain;
	}
	private List<ItemInstance> items = new ArrayList<ItemInstance>();
	public void addItem(ItemInstance theItem){
		items.add(theItem);
	}
	public void removeItem(ItemInstance theItem){
		items.remove(theItem);
	}
	public Integer getItemCount(){
		return items.size();
	}
	public ItemInstance getItem(Integer index){
		return items.get(index);
	}
	private CreatureInstance creature = null;
	public CreatureInstance getCreature(){
		return creature;
	}
	public void setCreature(CreatureInstance theCreature){
		creature = theCreature;
	}

	public LayerCell(LayerColumn theColumn){
		setColumn(theColumn);
	}

	private void setColumn(LayerColumn theColumn) {
		layerColumn = theColumn;
	}
	public LayerColumn getColumn(){
		return layerColumn;
	}
	public Configuration getConfiguration(){
		return getColumn().getConfiguration();
	}
	public Atlas getAtlas(){
		return getColumn().getAtlas();
	}
	public Layer getLayer(){
		return getColumn().getLayer();
	}
	public Integer getRowId(){
		Iterator<Map.Entry<Integer,LayerCell>> iterator = getColumn().entrySet().iterator();
		while(iterator.hasNext()){
			Map.Entry<Integer,LayerCell> entry = iterator.next();
			if(entry.getValue().equals(this)){
				return entry.getKey();
			}
		}
		return null;
	}
}
